package com.likou.written.zhijia;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * Author: 陈桂明
 * Date: 2025/10/12 21:47
 * Description: zhijia1
 */
public class zhijia1 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        // while (in.hasNextInt()) { // 注意 while 处理多个 case
        //     int a = in.nextInt();
        //     int b = in.nextInt();
        //     System.out.println(a + b);
        // }
        int n = in.nextInt();
        int[][] letter = new int[n][2];

        for (int i = 0; i < n; i++) {
            letter[i][0] = in.nextInt();
            letter[i][1] = in.nextInt();
        }

        Arrays.sort(letter, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if (o1[0] == o2[0]) {
                    return o1[1] - o2[1];
                }

                return o1[0] - o2[0];
            }
        });

        // System.out.println(Arrays.deepToString(letter));

        int[] dp = new int[n];
        Arrays.fill(dp, 1);
        int ans = 1;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (letter[j][1] < letter[i][1]) {
                    dp[i] = Math.max(dp[i], dp[j] + 1);
                }
            }

            if (dp[i] > ans) {
                ans = dp[i];
            }
        }

        System.out.println(ans);
    }

}
